package cn.wsalix.order.entity;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import cn.anlaser.entity.BasicEntity;
import cn.wsalix.order.status.OrderEnum;
import cn.wsalix.shop.entity.Product;
import cn.wsalix.shop.status.PayEnum;
import cn.wsalix.type.PayTypeEnum;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "ORDER_INFO")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@EntityListeners({ AuditingEntityListener.class })
@Data
@EqualsAndHashCode(exclude={"order","product"},callSuper = false)
@ToString(exclude = {"order", "product"})
public class OrderInfo extends BasicEntity {	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7245697631565191281L;
	@Id
	private Long id;
	@JsonIgnore
	@OneToOne(optional = false, cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
	@MapsId
	@JoinColumn(name = "ID")
	private Order order;
	private String tradeNo;// 订单号
	private String avatar;//购买人头像
	private String orderDate;
	private OrderEnum status;//订单状态
	private int amount;//
	private Integer postfree;
	@ManyToOne(cascade = CascadeType.MERGE, optional = true, fetch = FetchType.LAZY)
	@JoinColumn(foreignKey = @ForeignKey(name = "FK_ORDERINFO_PRODUCT"), name = "PRODUCT_ID")
	private Product product;
/*	@OneToOne(optional = false, cascade = CascadeType.MERGE)
	@JoinColumn(name = "ORDER_ID", referencedColumnName = "ID", unique = true)
	private Order order;*/
	private int num;
//
	private PayTypeEnum payType;
	private PayEnum pay;

	private String payTypeTitle;
	private String payTitle;
	
	private String customerName;
	private String phone;
	private String address;
	private String zipCode;
	
	private String express;//快递
	private String expressNo;//快递编号
	private String expressPhone;//快递电话
}